<template>
  <div class="user-wrapper">
    <div class="content-box">

      <screenfull class="screenfull action"/>
      <a-dropdown>
        <span class="action ant-dropdown-link user-dropdown-menu">
          <a-avatar :src="avatar" class="avatar" size="small"/>
          <span>{{ nickname }}</span>
        </span>

        <a-menu class="user-dropdown-menu-wrapper" slot="overlay">

          <a-menu-item key="8">
            <a @click="setPassword" href="javascript:;">
              <a-icon type="key"/>
              <span>修改密码</span>
            </a>
          </a-menu-item>
          <a-menu-divider/>

          <a-menu-item key="5">
            <a @click="handleLogout" href="javascript:;">
              <a-icon type="logout"/>
              <span>退出登录</span>
            </a>
          </a-menu-item>
        </a-menu>
      </a-dropdown>
    </div>
  </div>
</template>

<script>
//  import NoticeIcon from '@/components/NoticeIcon'
  import { mapActions, mapGetters } from 'vuex'
  import Screenfull from '@/components/Screenfull'
  export default {
    inject: ['upShow','SetPwdModal'],
    name: 'UserMenu',
    components: {
//      NoticeIcon,
      Screenfull
    },
    mounted(){
      console.log("路由表是",this.routers)
    },
    computed: {
      ...mapGetters(['nickname', 'avatar','routers'])

    },
    methods: {
      ...mapActions(['Logout']),
      handleLogout() {
        this.$confirm({
          title: '提示',
          content: '真的要注销登录吗 ?',
          onOk: () => {
            return this.Logout({}).then(() => {
              setTimeout(() => {
                window.location.reload()
              }, 16)
            }).catch(err => {
              this.upShow(2,{
                title: '错误',
                description: err.message
              })
            })
          },
          onCancel() {
          }
        })
      },
      checkPerms(routeName){
        let perms = this.routers.map(route => {
          return route.name
        })
        return  perms.indexOf(routeName) > -1
      },
      setPassword(){
        this.SetPwdModal()
      }
    }
  }
</script>
